//
//  ZhenYanTableViewCell.m
//  TQY
//
//  Created by 甘世清 on 2024/7/7.
//

#import "ZhenYanTableViewCell.h"
#import "WritingPopView.h"
@implementation ZhenYanTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)SQ_Style:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    UIView * bgView = [[UIView alloc]init];
    bgView.layer.cornerRadius = 4;
    bgView.layer.masksToBounds = YES;
    bgView.backgroundColor = UIColor.whiteColor;
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(10, 12, 0, 12));
    }];
    UIView * line1 = [[UIView alloc]init];
    line1.backgroundColor = SQColorF1F1F1;
    [bgView addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(bgView);
            make.height.mas_equalTo(1);
            make.top.equalTo(bgView).offset(64);
    }];

    [bgView addSubview:self.headerView];
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(44);
            make.left.equalTo(bgView).offset(12);
        make.top.equalTo(bgView).offset(10);
    }];
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView.mas_right).offset(8);
        make.top.equalTo(self.headerView).offset(4);
        make.height.mas_equalTo(22);
    }];
    
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView.mas_right).offset(8);
        make.bottom.equalTo(self.headerView.mas_bottom).offset(-4);
        make.height.mas_equalTo(14);
    }];
    [self.contentView addSubview:self.moreBtn];
    [self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.nameLabel);
            make.width.mas_equalTo(60);
            make.right.equalTo(bgView.mas_right);
            make.height.mas_equalTo(50);
    }];
    
    [bgView addSubview:self.messageLabel];
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(bgView).offset(10);
            make.top.equalTo(line1.mas_bottom).offset(10);
            make.right.equalTo(bgView.mas_right).offset(-10);
    }];
    WS(weakSelf);
    [self.moreBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_reportButtonClick];
    }];
    
    self.FS_cellBottomView = self.messageLabel;
    
}

- (void)setModel:(MottoModel *)model{
    _model = model;
    self.messageLabel.text = model.content;
    [self.headerView.headerImage sd_setImageWithURL:SQURLImage(model.portrait) placeholderImage:SQGetImage(@"1")];
    self.nameLabel.text = model.name;
    self.timeLabel.text = model.createTime;
}

-(void)SQ_headerViewButtonClick{
    PeopleDetailViewController * vc = [[PeopleDetailViewController alloc]init];
    vc.uid = self.model.uid;
    [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
}

-(void)SQ_reportButtonClick{
    WritingPopView * vc = [[WritingPopView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDETH, 260+FootHeight)];
    vc.uid = self.model.uid;
    LSTPopView * pop = [LSTPopView initWithCustomView:vc
                                             parentView:nil
                                               popStyle:LSTPopStyleSmoothFromBottom dismissStyle:LSTDismissStyleSmoothToBottom];
    pop.hemStyle = LSTHemStyleBottom;
    [pop pop];
    LSTPopViewWK(pop)
    [pop setBgClickBlock:^{
        [wk_pop dismiss];
    }];
    WS(weakSelf);
    [vc.pingbiBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_mottoHide];
        [wk_pop dismiss];
    }];
    [vc.quxiaoBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [wk_pop dismiss];
    }];
}
-(void)SQ_mottoHide{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:self.model.userid forKey:@"rid"];
    [HttpTool post:@"motto/hide" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        if (self.hideWritingouchBlock) {
            self.hideWritingouchBlock(self.model);
        }
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
}

- (SQCustomButton *)moreBtn{
    if (!_moreBtn) {
        _moreBtn = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(16, 16) midmargin:0];
        _moreBtn.image = SQGetImage(@"gengduo");
    }
    return _moreBtn;
}
- (UILabel *)messageLabel{
    if (!_messageLabel) {
        _messageLabel = [[UILabel alloc]init];
        _messageLabel.font = FONT_MEDIUM(14);
        _messageLabel.textColor = SQColor333333;
        _messageLabel.backgroundColor = UIColor.clearColor;
        _messageLabel.numberOfLines = 0;
    }
    return _messageLabel;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT_MEDIUM(16);
        _nameLabel.textColor = SQColor333333;
        _nameLabel.backgroundColor = UIColor.clearColor;
        _nameLabel.numberOfLines = 0;
    }
    return _nameLabel;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.font = FONT_REGULAR(10);
        _timeLabel.textColor = SQColor999999;
        _timeLabel.backgroundColor = UIColor.clearColor;
    }
    return _timeLabel;
}
- (HeaderView *)headerView{
    if (!_headerView) {
        _headerView = [[HeaderView alloc]init];
        _headerView.headerImage.contentMode = UIViewContentModeScaleAspectFill;
        _headerView.clipsToBounds = YES;
        [_headerView.btn addTarget:self action:@selector(SQ_headerViewButtonClick) forControlEvents:UIControlEventTouchUpInside];
        _headerView.layer.cornerRadius = 22;
        _headerView.layer.masksToBounds = YES;
    }
    return _headerView;
}
@end
